using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ProjectileImpactEffect:ProjectileImpactEffectBase {
	[SerializeField] float timePause;
	[SerializeField] float screenShake;

	void CreateEffect(Vector2 position,Vector2 normal,ParticleCreator particleCreator,bool intense,float size = 1) {

		if(intense) {
			CameraController.instance.AddScreenShake(screenShake);
			Utility.WaitSync(timePause);
		}

		if(particleCreator!=null)
			particleCreator.CreateParticleAt(position,new Angle(normal),size);
	}

	protected override void ProjectileHitMobEventHandler(object sender,ProjectileHitEventArgs e) {
		ParticleCreator particleCreator = e.target;
		CreateEffect(e.position,e.normal,particleCreator,true);
	}
	protected override void ProjectileHitWallEventHandler(object sender,ProjectileHitEventArgs e) {
		TileData target = TilemapController.GetTileAt(e.position-(e.normal.normalized*0.5f));
		ParticleCreator particleCreator = target;
		CreateEffect(e.position,e.normal,particleCreator,false,Mathf.Sqrt(e.stat.size));
	}
	protected override void ProjectileDestroyEventHandler(object sender,ProjectileEventArgs e) {
		Projectile proj = sender as Projectile;

		Vector2 position = transform.position;
		Vector2 normal = -proj.velocity;
		CreateEffect(position,normal,null,false);
	}

}